{include file="common/_header"}

<body>

    <div class="x-body layui-anim layui-anim-up">
        <form class="layui-form">
            <input type="hidden" name="user_id" value="{$data.user_id|default=0}">
            <table id="table" lay-size="sm" class="tables layui-table">
                <colgroup>
                    <col width="100">
                    <col width="250">
                    <col width="100">
                    <col width="250">
                </colgroup>
                <tbody>
                <tr>
                    <td><span class="x-red">*</span>姓名</td>
                    <th><input type="text" name="real_name" placeholder="请输入" value="{$admin.real_name}" autocomplete="off" class="layui-input"></th>
                    <td>联系电话</td>
                    <th><input type="text" name="phone"  placeholder="请输入" value="{$admin.phone}" autocomplete="off" class="layui-input"></th>
                </tr>
                <tr>
                    <td><span class="x-red">*</span>管理员账号</td>
                    <th><input type="text" name="user_name" placeholder="请输入" value="{$admin.user_name}" id="user_name" lay-verify="user_name" autocomplete="off" class="layui-input"></th>
                    <td>密码</td>
                    <th><input type="password" name="user_pass" id="user_pass"  placeholder="不填密码默认456789" autocomplete="off" class="layui-input"></th>
                </tr>
                <tr>
                    <td>邮箱</td>
                    <th><input type="text" name="email" placeholder="请输入" value="{$admin.email}" autocomplete="off" class="layui-input"></th>
                    <td>状态</td>
                    <th>
                        <select name="status">
                            <option value="1" {if $admin.status == 1}selected{/if}>正常</option>
                            <option value="0" {if $admin.status == 2}selected{/if}>异常</option>
                        </select>
                    </th>
                </tr>
                <tr>
                    <td {if $admin.shop_id != 0}style="display:none"{/if}><span class="x-red">*</span>用户组</td>
                    <th {if $admin.shop_id != 0}style="display:none"{/if}>
                        <select name="group_id">
                            {volist name="data.group" id="val"}
                            <option value="{$val.group_id}" {if $val.group_id == $admin.group_id}selected{/if}>{$val.group_name}</option>
                            {/volist}
                        </select>
                    </th>
                    <td>备注</td>
                    <th><input type="text" name="remark" value="{$admin.remark}"  placeholder="请输入" autocomplete="off" class="layui-input"></th>
                </tr>
                </tbody>
            </table>
            <div style="margin-top: 30px; margin-right: 20px; text-align: right">
                <button type="button" lay-submit lay-filter="add" class="layui-btn" >立即提交</button>
            </div>
        </form>
    </div>
</body>

<script>
    layui.use('form', function(){
        var form = layui.form;

        form.verify({
            user_name: function(value, item){ //value：表单的值、item：表单的DOM对象
                if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
                    return '用户名不能有特殊字符';
                }
                if(/(^\_)|(\__)|(\_+$)/.test(value)){
                    return '用户名首尾不能出现下划线\'_\'';
                }
                // if(/^\d+\d+\d$/.test(value)){
                //     return '用户名不能全为数字';
                // }
            },

        });


        form.on('submit(add)', function (data) {
            $.ajax({
                'url': 'boxeadmin',
                'type': 'post',
                'data': data.field,
                'dataType': 'json',
                success: function (data) {
                    if(data.code == 1){
                        layer.msg(data.msg, {
                            icon: 6,
                            time: 800,
                        },function () {
                            window.parent.location.href = data.url;
                        })
                    }
                }
            });
        })
    });

</script>

{include file="common/_bottom"}